package me.militch.quickcore.core;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;

import java.util.List;

public class DaggerFragmentCallback<T> {
    private List<Fragment> fragments;
    private T call;
    public DaggerFragmentCallback(Activity activity,T call){
        this.call = call;
        if(activity instanceof AppCompatActivity){
            fragments = ((AppCompatActivity) activity).getSupportFragmentManager().getFragments();
        }
    }
    @SuppressWarnings("unchecked")
    public void callInject(){
        for(Fragment fragment : fragments){
            if(fragment instanceof HasDaggerInject){
                HasDaggerInject<T> hasDaggerInject = (HasDaggerInject<T>) fragment;
                hasDaggerInject.inject(call);
            }
        }
    }
}
